package com.yanqu.road.server.cmd.systemgroup.newmonopolymkt;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossAppointCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketGroup;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_NEW_MONOPOLY_MARKET_EXIT, desc = "玩家离线 和离开榷署座位")
public class CrossMonopolyMarketEixtCmd extends CrossAppointCommand {

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketExitReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketExitReqMsg.parseFrom(packet.getBytes());

        CrossNewMonopolyMarketGroup monopolyMarket = CrossNewMonopolyMarketMgr.getMarket(groupId);
        if(monopolyMarket == null){
            return;
        }
        if(req.getIsOffOnline() || req.getIsExitMonopolyMarket()){
            monopolyMarket.exitAllSeat(userId);
            return;
        }
        if(req.getExitOfficeSeatIndex() > 0 ){
            monopolyMarket.getMarketOffice().exitOfficeSeat(req.getExitOfficeSeatIndex(),userId);
        }
        if(req.getExitResGrabKingSeatIndex() > 0){
            monopolyMarket.getMarketResRob().exitPoint(req.getResGroupId(), req.getExitOfficeSeatIndex(),userId);
        }
        if(req.getExitResGrabQueenSeatIndex() > 0){
            monopolyMarket.getMarketResRob().exitPoint(req.getResGroupId(),req.getExitOfficeSeatIndex(),userId);
        }
    }

    @Override
    public void sendData() {

    }
}
